package com.fh.shop.api.book.controller;

import com.fh.shop.api.book.biz.IBookService;
import com.fh.shop.api.book.param.BookQueryParam;
import com.fh.shop.api.book.po.Book;
import com.fh.shop.api.common.DataTableResult;
import com.fh.shop.api.common.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/api/books")
@Api(tags = "图书接口",description = "图书的前台API接口项目")
public class BookRestController {
    @Resource(name = "bookService")
    private IBookService bookService;

    @PostMapping
    @ApiOperation("图书的增加方法")
    public ServerResponse add(Book book){
        return bookService.addBook(book);
    }

    @ApiOperation("图书的条件、分页查询")
    @GetMapping
    public DataTableResult list(BookQueryParam bookQueryParam){
        return bookService.findList(bookQueryParam);
    }


    @ApiOperation("回显")
    @ApiImplicitParam(name = "id",value = "根据id查询一条数据",dataType = "java.lang.Long",required = true,example = "0")
    @GetMapping("{id}")
    public ServerResponse find(@PathVariable Long id){
        return bookService.findBook(id);
    }

    @PutMapping
    @ApiOperation("修改")
    public ServerResponse update(@RequestBody Book book){
        return bookService.updateBook(book);
    }

    @ApiOperation("单个删除")
    @DeleteMapping("{bookId}")
    @ApiImplicitParam(name = "bookId",value = "根据id删除一条数据",example = "0",required = true)
    public ServerResponse delete(@PathVariable("bookId") Long id){
        return bookService.deleteBook(id);
    }

    @ApiOperation("批量删除")
    @ApiImplicitParam(name = "ids",value = "传多个id进行批量删除,如1,2,3...")
    @DeleteMapping
    public ServerResponse deleteBatch(String ids){
        return bookService.deleteBatch(ids);
    }
}
